class CommandUtils {
  static CommandUtils? _instanse;

  CommandUtils._();

  static CommandUtils get instance => _instanse ??= CommandUtils._();

  static const PROTOCOL_FLAG = 0x4D;
  static const FILE_PROTOCOL_FLAG_D8 = 0xD8;
  static const FILE_PROTOCOL_FLAG_D9 = 0xD9;

  static const CMD_01 = 0x01;
  static const CMD_02 = 0x02;
  static const CMD_03 = 0x03;
  static const CMD_04 = 0x04;
  static const CMD_05 = 0x05;
  static const CMD_06 = 0x06;
  static const CMD_07 = 0x07;
  static const CMD_C1 = 0xC1;
  static const CMD_C2 = 0xC2;
  static const CMD_C3 = 0xC3;

  List<int> _generalSendBytes(commandId, commandKey, List<int>? data) {
    int dataLength = data?.length ?? 0;

    List<int> sendBytes = [
      PROTOCOL_FLAG,
      commandId,
      commandKey,
      0x00,
      dataLength,
    ];
    if (data != null) {
      sendBytes.addAll(data);
    }
    return sendBytes;
  }

  List<int> bindCommand(List<int> data) {
    return _generalSendBytes(CMD_01, CMD_01, data);
  }
}
